package com.kaiwukj.android.ufamily.mvp.ui.page.keeper;

import android.widget.Button;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.kaiwukj.android.ufamily.R;
import com.kaiwukj.android.ufamily.mvp.http.entity.result.KeeperResult;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;

public class KeeperPickerAdapter extends BaseQuickAdapter<KeeperResult, BaseViewHolder> {

    private int flag = 0;

    public KeeperPickerAdapter() {
        super(R.layout.item_keeper_pick, new ArrayList<>());
        addChildClickViewIds(R.id.btn_detail, R.id.btn_pick);
    }

    @Override
    public long getItemId(int position) {
        return getItem(position) == null ? -1 : getItem(position).getHousekeeperId();
    }

    public void setFlag(int flag) {
        this.flag = flag;
    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, KeeperResult result) {
        Glide.with(getContext())
                .load(result.getHeadImg())
                .placeholder(R.drawable.picture_image_placeholder)
                .into((ImageView) holder.getView(R.id.iv_avatar));

        holder.setText(R.id.tv_name, result.getName());
        holder.setImageResource(R.id.iv_gender, result.isBoy() ? R.mipmap.ic_gender_boy : R.mipmap.ic_gender_girl);
        holder.setText(R.id.tv_age, String.format("%s岁", result.getAge()));
        holder.setText(R.id.tv_phone, result.getPhone());


        if (flag > 0) {
            //Button btnDetail = holder.getView(R.id.btn_detail);
            Button btnPick = holder.getView(R.id.btn_pick);
            btnPick.setText("发消息");
            holder.setVisible(R.id.rating_keeper, false);
        }
    }
}
